package com.appwoo.txtws.thread;

import android.content.Context;
import android.os.AsyncTask;
import android.view.View;
import android.widget.ProgressBar;
import com.appwoo.txtws.component.Global;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

public class APKDownloadTask extends AsyncTask<View, Integer, Integer>
{
  private String apkpath;
  private Context context;
  private int fileSize;
  private String filename;
  private FileOutputStream fos;
  private InputStream is;
  private Boolean isCancelDownload = Boolean.valueOf(false);
  private String keyid;
  private ProgressBar pbCurrent;

  protected Integer doInBackground(View[] paramArrayOfView)
  {
    this.filename = this.apkpath.substring(1 + this.apkpath.lastIndexOf("/"));
    try
    {
      URLConnection localURLConnection = new URL(this.apkpath).openConnection();
      localURLConnection.connect();
      this.is = localURLConnection.getInputStream();
      this.fileSize = localURLConnection.getContentLength();
      this.pbCurrent.setMax(this.fileSize);
      if (this.fileSize <= 0)
        throw new RuntimeException(this.context.getString(2131427562));
    }
    catch (Exception localException)
    {
      this.fileSize = -1;
      localException.printStackTrace();
      return Integer.valueOf(this.fileSize);
      if (this.is == null)
        throw new RuntimeException("stream is null");
    }
    finally
    {
      this.isCancelDownload = Boolean.valueOf(false);
      com.appwoo.txtws.service.WebTimeControlService.isWho = Integer.valueOf(1);
    }
    label204: byte[] arrayOfByte;
    int i;
    if (Global.isSDCard())
    {
      this.fos = new FileOutputStream(Global.SOFTPATHSDCARD + this.filename);
      arrayOfByte = new byte[1024];
      i = 0;
    }
    while (true)
    {
      boolean bool = this.isCancelDownload.booleanValue();
      if (bool);
      int j;
      do
      {
        this.isCancelDownload = Boolean.valueOf(false);
        com.appwoo.txtws.service.WebTimeControlService.isWho = Integer.valueOf(1);
        break;
        this.fos = this.context.openFileOutput(this.filename, 1);
        break label204;
        com.appwoo.txtws.service.WebTimeControlService.isWho = Integer.valueOf(0);
        j = this.is.read(arrayOfByte);
      }
      while (j == -1);
      this.fos.write(arrayOfByte, 0, j);
      i += j;
      Integer[] arrayOfInteger = new Integer[1];
      arrayOfInteger[0] = Integer.valueOf(i);
      publishProgress(arrayOfInteger);
    }
  }

  public String getApkpath()
  {
    return this.apkpath;
  }

  public Context getContext()
  {
    return this.context;
  }

  public String getKeyID()
  {
    return this.keyid;
  }

  protected void onPostExecute(Integer paramInteger)
  {
    this.pbCurrent.setProgress(0);
    this.pbCurrent.setVisibility(8);
    try
    {
      Boolean localBoolean = Boolean.valueOf(Global.isSDCard());
      if (paramInteger.intValue() >= 0)
        if (localBoolean.booleanValue())
          if (paramInteger.intValue() != -1)
            Global.installApk(this.context, Global.SOFTPATHSDCARD + this.filename);
      while (true)
      {
        if (this.is != null)
          this.is.close();
        if (this.fos == null)
          break;
        this.fos.close();
        return;
        if (paramInteger.intValue() != -1)
        {
          Global.installApk(this.context, Global.SOFTPATHMEMORY + this.filename);
          continue;
          paramInteger.intValue();
        }
      }
      return;
    }
    catch (Exception localException)
    {
    }
  }

  protected void onPreExecute()
  {
    this.pbCurrent.setVisibility(0);
  }

  protected void onProgressUpdate(Integer[] paramArrayOfInteger)
  {
    this.pbCurrent.setProgress(paramArrayOfInteger[0].intValue());
  }

  public void setApkpath(String paramString)
  {
    this.apkpath = paramString;
  }

  public void setContext(Context paramContext)
  {
    this.context = paramContext;
  }

  public void setProgressBar(ProgressBar paramProgressBar)
  {
    this.pbCurrent = paramProgressBar;
  }
}

/* Location:           C:\Documents and Settings\Administrator\classes_dex2jar.jar
 * Qualified Name:     com.appwoo.txtws.thread.APKDownloadTask
 * JD-Core Version:    0.6.2
 */